'use strict';
const Service = require('egg').Service;

class ShoppingService extends Service {
  // 删除购物车单条信息
  async destroy(id) {
    const { ctx } = this;
    try {
      const { ctx } = this;
      const { ShoppingCart } = this.app.model.Tables.Shop;
      const result = await ShoppingCart.destroy({
        where: {
          id,
          project_id: ctx.userInfo.project_id,
        },
      });
      return result > 0
        ? ctx.response.success('删除成功')
        : ctx.response.error(result, '删除失败');
    } catch (error) {
      console.log(error);
      return this.ctx.response.error(error.message);
    }
  }
}

module.exports = ShoppingService;
